package com.example.health_hjk;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.health_hjk.AboutAdapter;
import com.example.health_hjk.R;

import java.util.ArrayList;
import java.util.List;

public class AboutActivity extends AppCompatActivity {
    ViewPager aboutVp;
    TextView shareTv,phoneTv;

    LinearLayout pointLayout;
    List<View>viewList;
    //存放图片的数组
    int[]picIds = {R.mipmap.ab1,R.mipmap.ab2,R.mipmap.ab3,R.mipmap.ab4,R.mipmap.ab5};
    private AboutAdapter adapter;
    //延时自动滚动图片
    Handler handler = new Handler(){
        public void handleMessage(Message msg){
            int currentItem = aboutVp.getCurrentItem();
            aboutVp.setCurrentItem(currentItem + 1);
            handler.sendEmptyMessageDelayed(1,5000);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);

        aboutVp = findViewById(R.id.about_vp);
        shareTv = findViewById(R.id.about_tv_share);
        pointLayout = findViewById(R.id.about_layout_point);
        phoneTv = findViewById(R.id.about_tv_tel);

        OnClick onClick = new OnClick();
        phoneTv.setOnClickListener(onClick);
        shareTv.setOnClickListener(onClick);

        viewList = new ArrayList<>();
        //初始化viewpager页面信息
        for(int i = 0; i < picIds.length; i++){
            View view = LayoutInflater.from(this).inflate(R.layout.item_aboutvp,null);
            ImageView iv = view.findViewById(R.id.item_aboutvp_iv);
            iv.setImageResource(picIds[i]);
            viewList.add(view);
        }
        //创建适配器对象
        adapter = new AboutAdapter(viewList);
        //设置适配器
        aboutVp.setAdapter(adapter);
        //发送切换页面信息
        handler.sendEmptyMessageDelayed(1,5000);
    }
    class OnClick implements View.OnClickListener {

            public void onClick(View v){
                switch (v.getId()) {
                    case R.id.about_tv_tel:

                        Intent intent = new Intent(Intent.ACTION_DIAL);
                        Uri data = Uri.parse("tel:" + "123456");
                        intent.setData(data);
                        startActivity(intent);

                        break;
                    case R.id.about_tv_share:
                        Intent intent_t = new Intent(Intent.ACTION_SEND);
                        intent_t.setType("text/plain");
                        String msg = "健康饮食很重要，请下载app了解更多";
                        intent_t.putExtra(Intent.EXTRA_TEXT,msg);
                        startActivity(Intent.createChooser(intent_t,"健康饮食分享"));
                        break;
                }
            }
        }
    }
